import java.io.*;

public class FileCopy
{
    public void copyIO(InputStream is, OutputStream os) throws IOException
    {
        byte buf[] = new byte[4096];
        int len = is.read(buf);
        while (len != -1)
        {
            os.write(buf, 0, len);
            len = is.read(buf);
        }
    }

    public static void main(String[] args)
    {
        File input = new File(args[0]);
        if (!input.exists())
        {
            System.err.println("源文件不存在");
            System.exit(1);
        }
        File output = new File(args[1]);
        if (output.exists())
        {
            System.err.println("目标文件已存在");
            System.exit(1);
        }
        try
        {
            FileInputStream fis = new FileInputStream(input);
            FileOutputStream fos = new FileOutputStream(output);
            new FileCopy().copyIO(fis, fos);
            fis.close();
            fos.flush();
            fos.close();
        }
        catch (Exception e)
        {
            if (e instanceof FileNotFoundException)
            {
                System.err.println("源文件不存在");
                System.exit(1);
            }
            if (e instanceof IOException)
            {
                System.err.println("复制失败");
                System.exit(1);
            }
        }

    }
}
